package com.hxd.otc.module.my.activity;

import android.os.Bundle;
import android.support.constraint.ConstraintLayout;
import android.view.View;
import android.widget.TextView;

import com.hxd.otc.R;
import com.hxd.otc.base.BaseActivity;
import com.hxd.otc.common.UserHelper;
import com.hxd.otc.common.enums.CardLevelEnum;
import com.hxd.otc.common.enums.CountryCodeEnum;
import com.hxd.otc.module.my.bean.RealNameAuthRuleInfoBean;
import com.hxd.otc.module.my.contract.CertificationDetailContract;
import com.hxd.otc.module.my.presenter.CertificationDetailPresenter;
import com.hxd.otc.utils.ResourceUtil;
import com.hxd.otc.widget.TitleBar;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.OnClick;

/**
 * Created by lzy on 2018/12/5 0005.
 * description ${认证详情}
 */
public class CertificationDetailActivity extends BaseActivity<CertificationDetailPresenter> implements CertificationDetailContract.IView {
    @BindView(R.id.title_bar)
    TitleBar mTitleBar;
    @BindView(R.id.tv_title_v1)
    TextView mTvTitleV1;
    @BindView(R.id.tv_desc_v1)
    TextView mTvDescV1;
    @BindView(R.id.tv_status_v1)
    TextView mTvStatusV1;
    @BindView(R.id.cl_identity_authentication_v1)
    ConstraintLayout mClIdentityAuthenticationV1;
    @BindView(R.id.tv_title_v2)
    TextView mTvTitleV2;
    @BindView(R.id.tv_desc_v2)
    TextView mTvDescV2;
    @BindView(R.id.tv_status_v2)
    TextView mTvStatusV2;
    @BindView(R.id.tv_name)
    TextView mTvName;
    @BindView(R.id.cl_identity_authentication_v2)
    ConstraintLayout mClIdentityAuthenticationV2;

    @Override
    protected int getLayoutId() {
        return R.layout.activity_certification_detail;
    }

    @Override
    protected CertificationDetailPresenter createPresenter() {
        return new CertificationDetailPresenter(this);
    }

    @Override
    protected void initView() {
        mTvName.setText(UserHelper.getRealName());
        boolean isLevel1 = UserHelper.getCardLevel().equals(CardLevelEnum.LEVEL_1);
        boolean isLevel2 = UserHelper.getCardLevel().equals(CardLevelEnum.LEVEL_2);
        mTvStatusV2.setTextColor(ResourceUtil.getColor(isLevel2 ? R.color.color_FF5AC792 : R.color.color_FFEE5344));
        mTvStatusV2.setText(isLevel2 ? R.string.verified_success : R.string.unverified);
        mTvStatusV2.setCompoundDrawables(isLevel2 ? ResourceUtil.getDrawable(R.mipmap.icon_identity_authentication_complete) : null, null, null, null);
        mClIdentityAuthenticationV2.setEnabled(isLevel1);
    }

    @Override
    protected void initData() {
        mPresenter.getRealNameAuthRuleInfo();
    }

    @Override
    protected void initEvent() {
    }

    @OnClick({R.id.cl_identity_authentication_v2})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.cl_identity_authentication_v2:
                Bundle bundle = new Bundle();
                bundle.putSerializable(RealNameStep2Activity.EXTRA_REAL_NAME_TYPE, CountryCodeEnum.CHINA);
                $startActivity(RealNameStep1Activity.class, bundle, true);
                break;
        }
    }

    @Override
    public void getRealNameAuthRuleInfoSuccess(ArrayList<RealNameAuthRuleInfoBean> realNameAuthRuleInfoBeans) {
        if (realNameAuthRuleInfoBeans == null || realNameAuthRuleInfoBeans.size() == 0) {
            mTvDescV1.setText("");
            mTvDescV2.setText("");
            return;
        }
        String desc1 = "";
        String desc2 = "";

        for (RealNameAuthRuleInfoBean realNameAuthRuleInfoBean : realNameAuthRuleInfoBeans) {
            if (RealNameAuthRuleInfoBean.V2.equals(realNameAuthRuleInfoBean.getCronKey())) {
                desc2 = realNameAuthRuleInfoBean.getCronValueDesc();
            } else if (RealNameAuthRuleInfoBean.V1.equals(realNameAuthRuleInfoBean.getCronKey())) {
                desc1 = realNameAuthRuleInfoBean.getCronValueDesc();
            }
        }
        mTvDescV1.setText(desc1);
        mTvDescV2.setText(desc2);
    }

    @Override
    public void getRealNameAuthRuleInfoFail(String errMessage) {
        mTvDescV2.setText("");
    }
}
